from bs4 import BeautifulSoup
headers={
    "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edg/114.0.1823.86"
}#此处使用headers将自己伪装成浏览器。
import requests
response = requests.get("http://books.toscrape.com/")#这是一个专门练习爬虫的网站。
content=response.text
soup=BeautifulSoup(content,"html.parser")
all_prices=soup.findAll("p",attrs={"class":"price_color"})
for price in all_prices:
    print(price.string)
all_titles=soup.findAll("h3")
for title in all_titles:
    all_links=title.findAll("a")
    for link in all_links:
        print(link.string)
# print(soup.p)
# print(response)
# print(response.status_code)
# if response.ok:
#     #获取响应内容
#     print(response.text)#以字符串储存响应内容。
# else:
#     print("请求失败")